# !/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# @Time: 2021/3/21 11:40

import configparser
import os

class Config(object):
    def __init__(self, config_file='config/config_weibo.ini'):
        self.init(config_file)

    def get(self, section, name):
        return self._config.get(section, name)

    def get_raw(self, section, name):
        return self._configRaw.get(section, name)

    def set(self,section,name,value):
        self._config.set(section,name,value)
        with open(self._path,'w') as fw:
            self._config.write(fw)

    def init(self, config_file='config/config_weibo.ini'):
        self._path = os.path.join(os.getcwd(), config_file)
        if not os.path.exists(self._path):
            raise FileNotFoundError("No such file: config_weibo.ini")
        self._config = configparser.ConfigParser()
        self._config.read(self._path, encoding='utf-8-sig')
        self._configRaw = configparser.RawConfigParser()
        self._configRaw.read(self._path, encoding='utf-8-sig')


global_config = Config()
